package com.itfenghuang.day14;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class A03_Server {
    public static void main(String[] args) throws IOException {
        //创建ServerSocket对象
        ServerSocket ss = new ServerSocket(10086);
        System.out.println("监听之前");
        // 监听连接 阻塞
        Socket socket = ss.accept();
        System.out.println("监听之后");
        //获取输入流
        InputStream is = socket.getInputStream();
        //获取输出流
        OutputStream os = socket.getOutputStream();
        byte[] bys=new byte[1024];
        System.out.println("获取客户端发送消息之前");
        int i = is.read(bys);//读取客户端发送的数据  阻塞
        System.out.println("获取客户端发送消息之后");
        System.out.println(new String(bys,0,i));
        //返回给客户端
        os.write(bys,0,i);
        socket.close();

    }
}
